package com.zimmur.app.mocolink.manage.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zimmur.app.mocolink.domain.model.GoodsType;
import com.zimmur.app.mocolink.domain.model.GroupScene;
import com.zimmur.app.mocolink.domain.vo.GroupSceneVo;
import com.zimmur.app.mocolink.manage.web.common.ReturnJsonEntity;
import com.zimmur.app.mocolink.manage.web.common.StatusCodeEnum;
import com.zimmur.app.mocolink.service.IGroupSceneService;

@Controller
@RequestMapping("/groupScene")
public class GroupGoodsSceneController extends BaseController {

	@Autowired
	private IGroupSceneService groupSceneService;
	@RequestMapping("/index")
	public String index(HttpServletRequest request,ModelMap model){
		List<GroupSceneVo> sceneList=groupSceneService.getAllScene();
		model.addAttribute("sceneList", sceneList);
		return "/center/groupGoodsScene/list";
	}
	@RequestMapping("/edit")
	public String edit(HttpServletRequest request,ModelMap model){
		Integer sceneId = getParam("sceneId", 0);
		GroupScene groupScene = groupSceneService.selectById(sceneId);
		List<GroupSceneVo> sceneList = groupSceneService.getAllScene();
		model.addAttribute("sceneList", sceneList);
		model.addAttribute("groupScene", groupScene);
		return "/center/groupGoodsScene/edit";
	}
	@RequestMapping("/add")
	public String add(HttpServletRequest request,ModelMap model){
		List<GroupSceneVo> list = groupSceneService.getAllScene();
		model.addAttribute("sceneList", list);
		model.addAttribute("groupScene", new GroupScene());
		return "/center/groupGoodsScene/edit";
	}
	@ResponseBody
	@RequestMapping("/save")
	public ReturnJsonEntity save(GroupScene groupScene){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		int flag = 0;
		if(groupScene.getId()!=null && groupScene.getId()>0){
			flag = groupSceneService.update(groupScene);
		}else{
			flag = groupSceneService.add(groupScene);
		}
		if(flag>0){
			codeEnum = StatusCodeEnum.CODE000000;	
		}
		entity.init(codeEnum);
		return entity;
	}
	@ResponseBody
	@RequestMapping("/delete")
	public ReturnJsonEntity delete(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer sceneId = getParam("sceneId",0);
		int flag = groupSceneService.delete(sceneId);
		if(flag>0){
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
}
